package configuration

import (
	"encoding/json"
	"fmt"
	"kop/modules/configuration/client"
	"kop/util/log"
)

func init() {

	var err error
	if err = json.Unmarshal(client.Load("IslandTemplate"), &IslandConfigs); err != nil {
		panic(err)
	}

	log.Info("Load IslandTemplate.json success.")

}

type IslandConf struct {
	IslandID int32 `json:"ID"` // 索引，无含义
	Page     int32 // 页数最大
	Level    int32 // 等级
	Income   int32 // 每分钟收益
	Power    int64 // NPC队伍战力
	NPCLevel int32 // NPC等级
	NPC1     int32 // NPC1
	NPC2     int32 // NPC2
	NPC3     int32 // NPC3
	NPC4     int32 // NPC4
	NPC5     int32 // NPC5
}

var (
	IslandConfigs []IslandConf
)

func GetByIslandID(islandID int32) IslandConf {

	for _, v := range IslandConfigs {
		if v.IslandID == islandID {
			return v
		}
	}

	panic(fmt.Errorf("IslandID not found [%d]", islandID))
}

func GetIslandsByPage(page int32) []IslandConf {

	var configs []IslandConf
	for _, v := range IslandConfigs {
		if v.Page == page {
			configs = append(configs, v)
		}
	}

	return configs
}
